﻿namespace NetFx.MSIL
{

  using System;
  using System.Text;
  using System.Collections;

  using System.Reflection;
  using System.Reflection.Emit;
  using System.Runtime.InteropServices;

  using System.Diagnostics;
  using System.Diagnostics.CodeAnalysis;
  using System.Diagnostics.SymbolStore;

  public class PropertyGenerator : MemberGenerator
  {
    #region Statics
    public static PropertyGenerator of(PropertyBuilder builder)
    {
      return new PropertyGenerator(builder);
    }
    #endregion
    #region Fields
    protected object defaultValue = null;
    #endregion
    #region Properties
    public override DefType GeneratorType
    {
      get
      {
        return DefType.Property;
      }
    }

    public virtual PropertyBuilder Builder
    {
      get
      {
        return this.builder as PropertyBuilder;
      }
    }
    public virtual PropertyAttributes Attributes
    {
      get
      {
        return this.Builder.Attributes;
      }
    }
    public virtual bool CanRead
    {
      get
      {
        return this.Builder.CanRead;
      }
    }
    public virtual bool CanWrite
    {
      get
      {
        return this.Builder.CanWrite;
      }
    }
    public virtual Type PropertyType
    {
      get
      {
        return this.Builder.PropertyType;
      }
    }
    public virtual PropertyToken PropertyToken
    {
      get
      {
        return this.Builder.PropertyToken;
      }
    }
    public virtual object DefaultValue
    {
      get
      {
        return this.defaultValue;
      }
      set
      {
        this.Builder.SetConstant(this.defaultValue = value);
      }
    }
    public virtual bool IsSpecialName
    {
      get
      {
        return this.Builder.IsSpecialName;
      }
    }
    #endregion
    #region Constructors
    public PropertyGenerator(PropertyBuilder builder):base(builder)
    {

    }
    #endregion
    #region Methods
    public virtual MethodInfo AddMethod(MethodBuilder method)
    {
      this.Builder.AddOtherMethod(method);
      return method;
    }
    public virtual MethodInfo GetGetter()
    {
      return this.Builder.GetGetMethod();
    }
    public virtual MethodInfo GetGetter(bool nonPublic)
    {
      return this.Builder.GetGetMethod(nonPublic);
    }
    public virtual MethodInfo SetGetter(MethodBuilder getter)
    {
      this.Builder.SetGetMethod(getter);
      return getter;
    }
    public virtual MethodInfo GetSetter()
    {
      return this.Builder.GetSetMethod();
    }
    public virtual MethodInfo GetSetter(bool nonPublic)
    {
      return this.Builder.GetSetMethod(nonPublic);
    }
    public virtual MethodInfo SetSetter(MethodBuilder setter)
    {
      this.Builder.SetSetMethod(setter);
      return setter;
    }
    public virtual MethodInfo[] GetAccessors()
    {
      return this.Builder.GetAccessors();
    }
    public virtual MethodInfo[] GetAccessors(bool nonPublic)
    {
      return this.Builder.GetAccessors(nonPublic);
    }
    #endregion
    #region Utils
    protected override void Dispose(bool disposing)
    {
      if (disposing)
      {
        this.defaultValue = null;
      }
      base.Dispose(disposing);
    }
    #endregion
  }
}